package com.marisfrolg.scan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.marisfrolg.scan.dao.PermissionDao;
import com.marisfrolg.scan.mapper.PermissionMapper;
import com.marisfrolg.scan.service.PermissionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, PermissionDao> implements PermissionService {

    @Resource
    private PermissionMapper permissionMapper;

    @Override
    public PermissionDao getByUrl(String path) {
        LambdaQueryWrapper<PermissionDao> lqw = new LambdaQueryWrapper<>();
        lqw.eq(PermissionDao::getUrl, path);
        return permissionMapper.selectOne(lqw);}

    @Override
    public List<PermissionDao> getByService(String serviceName) {
        LambdaQueryWrapper<PermissionDao> lqw = new LambdaQueryWrapper<>();
        lqw.eq(PermissionDao::getService, serviceName);
        return permissionMapper.selectList(lqw);
    }

    @Override
    public void updateStatus2forbidden(String serviceName) {
        System.out.println("------------333333---------");
        PermissionDao dao = new PermissionDao();
        dao.setStatus(0);
        dao.setService(serviceName);
        LambdaQueryWrapper<PermissionDao> lqw = new LambdaQueryWrapper<>();
        lqw.eq(PermissionDao::getService, serviceName);
        permissionMapper.update(dao, lqw);
    }
}
